/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2017-09-09 21:49:48
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.kb.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.itttq.kb.model.po.TopicReplyPo;

@Mapper
public interface ITopicReplyMapper extends BaseMapper<TopicReplyPo>{
	/**
	  * 获取根据更新时间排序的N条数据：
	  * @return
	  */
	@Select("select a.id,a.topic_title,a.topic_id,a.content,a.create_time,a.is_adopt,a.number_love,a.number_reply,a.reply_ip,a.update_time,b.avatar as creator_avatar,a.creator_id,b.`name` as creator_name from kb_topic_reply a,kb_user b where a.topic_id=#{id} and a.creator_id=b.id order by update_time desc limit #{start}, #{size}") 
	public List<TopicReplyPo> getTopicReplies(@Param("id")int id, @Param("start")int start, @Param("size")int size);
	
	/**
	  * 更新帖子点赞数
	 * 
	 * @param field	更新字段：love-点赞数；
	 * @param id	主题ID
	 * @Author 迷蝶
	 * @return int
	 */
	@Update({"<script>",
	    "update kb_topic_reply set ",
	    "<when test=\"field =='love'\"> number_love=number_love +1 </when>",
	    " where id =#{id}",
	    "</script>"})
	public int updateNumber(@Param("field")String field, @Param("id")int id);
	/**
	 * 更新帖子点赞数
	 * 
	 * @param field	更新字段：love-点赞数；
	 * @param id	主题ID
	 * @Author 迷蝶
	 * @return int
	 */
	@Delete("delete from kb_topic_reply  where topic_id =#{tid}")
	public int delTopicReplyByTid(@Param("tid")int tid);
}